<template>
  <div class="execution">
    <basic-container>
      <avue-crud
        v-model="form"
        v-bind="bindVal"
        v-on="onEvent"
        :page.sync="page"
        :permission="permissionList"
        :before-open="beforeOpen"
      >
        <template slot="menuRight">
          <el-button type="primary" size="small" @click="exportData">导出</el-button>
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
  import baseCrud from '@/mixins/base-crud'
  import { exportData,putObj } from '@/api/subway/swtkwhitecard'
  import {} from "@/const/crud/subway/swtkwhitecard";
  import { handleExcelResponse } from "@/util/util";
  import {dateFormat} from '@/util/date'

  export default {
    name: 'swtkwhitecard',
    mixins: [baseCrud('subway/swtkwhitecard')],
    data() {
      return {
      };
    },
    computed: {
      permissionList() {
        return {
        }
      }
    },
    methods: {
      async exportData(){ //导出
        let loading = this.$loading({
          lock: true,
          text: "Loading",
          spinner: "el-icon-loading",
          background: "rgba(0, 0, 0, 0.7)"
        })
        try {
          let tableSelect = this.$refs.crud.tableSelect
          if(tableSelect.length<=0){
              this.$message.warning("请选择至少一条数据！");
              return;
          }
          let ids = tableSelect.map(row => row.id)
          let param = {
            ids:ids
          };
          console.log(param)
          const res = await exportData(param);
          handleExcelResponse(res);
        } finally {
          loading.close();
        }
      },
      rowUpdate: function (row, done, loading) {
        if (JSON.stringify(row.filePath) === '{}' || row.filePath==null  || row.filePath==""){
            row.filePath="";	    
        }	
        putObj(row).then(data => {
          this.$message.success('修改成功')
          this.getList(this.page)
          done()
        }).catch(() => {
          loading()
        })
      },
    beforeOpen(done, type) {
      if (["view", "edit"].includes(type)) {
        // 查看和编辑逻辑
      } else {
        setTimeout(() => {
          this.form.sendDate=dateFormat(new Date()).slice(0,10);
        }, 0);
      }
      done();
    },
    }
  }
</script>

<style lang="scss" scoped>
.bottom-menu-close {
  text-align: center;
}
</style>
